﻿using HelenServer.UserCenter.Contracts;
using Microsoft.AspNetCore.Authorization;

namespace HelenServer.UserCenter.Controllers;

[ApiController]
[Route("[controller]")]
[Authorize]
public class UserController : ControllerBase
{
    private readonly IUserService _service;

    public UserController(IUserService service)
    {
        _service = service;
    }

    [HttpPost]
    [AllowAnonymous]
    public async Task<OperationResult> RegisterAsync([FromBody] UserCreateModel model)
    {
        var operation = HttpContext.GetOperation(model);

        var result = await _service.AddAsync(operation, HttpContext.RequestAborted);

        return result.Data == 1 ? OperationResult.OK(result.Data.ToString()) : OperationResult.Failed(result.Message);
    }
}